package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.Menu;
import com.atguigu.crowd.entity.MenuExample;
import com.atguigu.crowd.mapper.MenuMapper;
import com.atguigu.crowd.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * role的业务接口实现类
 *
 * @author wmb
 *
 * @since 2021-1-23
 */
@Service("menuService")
public class MenuServiceImpl implements MenuService {

    @Autowired
    @Qualifier("menuMapper")
    private MenuMapper menuMapper;

    /**
     * 查询所有的menu节点
     *
     * @return
     */
    @Override
    public List<Menu> getAll() {
        return menuMapper.selectByExample(new MenuExample());
    }

    /**
     * 保存menu
     *
     * @param menu
     */
    @Override
    public void saveMenu(Menu menu) {
       menuMapper.insert(menu);
    }

    /**
     * 更新menu
     *
     * @param menu
     */
    @Override
    public void updateMenu(Menu menu) {
        // 由于pid没有传入，一定要有选择性地更新，保证"pid"字段不会被置空
        menuMapper.updateByPrimaryKeySelective(menu);
    }

    /**
     * 根据id删除menu
     *
     * @param id
     */
    @Override
    public void removeMenuById(Integer id) {
        menuMapper.deleteByPrimaryKey(id);
    }
}
